# -*- coding: utf-8 -*-
from tornado import web, template, ioloop


class IndexHandler(web.RequestHandler):
    def get(self):
        arg = 'Template'
        self.write(f'<h1>Hello {arg}!</h1>')


class UserHandler(web.RequestHandler):
    def get(self):
        arg = 'Template'
        t = template.Template(f'<h1>Hello {{arg}}!</h1>')
        self.finish(t.generate(arg=arg))


class LoginHandler(web.RequestHandler):
    def get(self):
        arg = 'Template'
        loader = template.Loader('./templates/')
        self.finish(loader.load('index.html').generate(arg=arg))


class WelcomeHandler(web.RequestHandler):
    def get(self):
        arg = 'Template'
        self.render('index.html', arg=arg)


if __name__ == '__main__':
    app = web.Application([
        ('/', IndexHandler),
        ('/user/', UserHandler),
        ('/login/', LoginHandler),
        ('/welcome/', WelcomeHandler),
    ], debug=True,
        template_path='./templates')
    app.listen(8080)
    ioloop.IOLoop.current().start()
